import { HikvisionBaseService } from "../base";
import { hikvision } from "../type";

/**
 * 一卡通,门禁管理
 * - https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff95e951cefc54578b523d1738f65f0a1&tagPath=API列表-一卡通应用服务-门禁管理
 */
export class AcsDoorService extends HikvisionBaseService {
	/**
	 * 查询门禁点状态
	 * - https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700&version=%2Ff95e951cefc54578b523d1738f65f0a1&tagPath=API列表-一卡通应用服务-门禁管理#c149a7ff
	 * @param {string[]} doorIndexCodes 门禁点唯一标识，最大支持200个门禁点。查询门禁点列表v2接口获取返回参数doorIndexCode
	 * @return {*}
	 * @memberof AcsDoorService
	 */
	async getDoorStates(doorIndexCodes: string[]) {
		const url = `${this.config.baseUrl}/api/acs/v1/door/states`;
		const res = await this.curl<hikvision.isc.IResponse<hikvision.isc.IGetDoorStateResponse>>(
			url,
			{
				method: "POST",
				dataType: "json",
				contentType: "json",
				headers: {
					access_token: this.accessToken,
				},
				data: {
					doorIndexCodes,
				},
			}
		);
		this.handleResponseException(res, `查询门禁点状态出错`);
		return res.data.data;
	}

	/**
     * 门禁点反控
	 * todo
	 */
	async doControl() {}

	/**
     * 
     * 查询门禁点事件v2
     * 
     * @param {hikvision.isc.IGetDoorEventsRequestParams} params
     * @return {*} 
     * @memberof AcsDoorService
     */
    async getDoorEvents(params: hikvision.isc.IGetDoorEventsRequestParams) {
		const url = `${this.config.baseUrl}/api/acs/v2/door/events`;
		const res = await this.curl<
			hikvision.isc.IResponse<hikvision.isc.IGetDoorEventsResponse>
		>(url, {
			method: "POST",
			dataType: "json",
			contentType: "json",
			headers: {
				access_token: this.accessToken,
			},
			data: params,
		});
		this.handleResponseException(res, `查询门禁点事件出错`);
		return res.data.data;
	}
}
